package com.example.testlibraryproject.adapters;

import java.util.ArrayList;

import android.os.Message;
import android.widget.Button;
import android.widget.TextView;

import com.example.testlibraryproject.R;

public class MessagesListAdapterEndless extends EndlessAdapter {

	/** To store the latest fetched files */
	//MessagesListAdapter messagesListAdapter;
	ArrayList <Message> currentFetchedMessagesItems;
	//Context context;
	//OnMessageDismissBtnClickListener mOnMessageDismissBtnClickListener;
	static class ViewHolder{
		public TextView description;
		public Button dismissMsgBtn;
		public Button gotoGuideBtn;
	}

	public MessagesListAdapterEndless(MessagesListAdapter messagesListAdapter) {
		
		super(messagesListAdapter.getContext(), messagesListAdapter, R.layout.message_loading_view);
		//this.context = context;
		//this.messagesItems = Messages;
		//L.v("size of CustomListAdapter:"+Messages.size());
	}
	
		
	/**
	 * used to fetch data in background from ws and to
	 * @return true if new data found, false if no new data found 
	 */
	
	@Override
	protected boolean cacheInBackground() throws Exception {
		// TODO Auto-generated method stub
		/*L.v("inside cacheInBackground");
		int totalCount = ((MessagesListAdapter)getWrappedAdapter()).getCount();
		
		int currentPage = (totalCount/WSConstants.WS_MESSAGES_PER_PAGE) -1;
		
		L.v("Currently showing items count in adapter:"+totalCount+", current page:"+currentPage);
		
		
		String result = WebServices.wsGetUserMessages(currentPage+1, WSConstants.WS_MESSAGES_PER_PAGE);
		
		if(result != null ){
			
			currentFetchedMessagesItems = MessagesHelper.parseJsonToMessages(result);
			if(currentFetchedMessagesItems != null && currentFetchedMessagesItems.size()>0){
				return true;
			}
			
		}
		return false;*/
		//logic to fetch data here as it is being run in the back ground
		return true;
		
	}

	//will be used to add the fetched data to adapter
	@Override
	protected void appendCachedData() {
		// TODO Auto-generated method stub
		/*if(currentFetchedMessagesItems != null && currentFetchedMessagesItems.size()>0){
			L.v("Adding new items");
			((MessagesListAdapter)getWrappedAdapter()).addMessagesItems(currentFetchedMessagesItems);
			currentFetchedMessagesItems = null;
		}else{
			L.v("NO new items to add");
		}*/
		
		//Logic to add the data to the data set of the existgin adapter()
		
	}

}
